//
//  ZMBaseViewController.m
//  ZMKitDemo
//
//  Created by zm on 2018/6/13.
//  Copyright © 2018年 zm. All rights reserved.
//

#import "ZMBaseViewController.h"
#import "ZMNetErrorView.h"
#import "ZMLoadingView.h"
#import <FDFullscreenPopGesture/UINavigationController+FDFullscreenPopGesture.h>

@interface ZMBaseViewController ()<ZMNavigationBarDelegate>

@end

@implementation ZMBaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    [self buildUI];
}

- (void)buildUI {
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationController.navigationBar.translucent = false;
    self.fd_prefersNavigationBarHidden = true;
    self.navigationController.navigationBarHidden = true;
    _navBar = ({
        ZMNavigationBar *bar = [[ZMNavigationBar alloc] init];
        bar.delegate = self;
        [self.view addSubview:bar];
        bar;
    });
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Title
- (void)setTitle:(NSString *)title {
    _navBar.title = title;
}

- (NSString *)title {
    return _navBar.title;
}

#pragma mark - NetWork

- (void)showNetworkErrorView {
    [ZMNetErrorView dismissFromView:self.view];
    @weakify(self);
    [ZMNetErrorView showInView:self.view withRetryBolck:^(ZMNetErrorView *netErrorView) {
        @strongify(self);
        [self retry];
    }];
}

- (void)dismissNetworkErrorView {
    [ZMNetErrorView dismissFromView:self.view];
}

//在子类重写该方法
- (void)retry {
    
}

#pragma mark - Loading

- (void)showLoadingView {
    [ZMLoadingView dismissFromView:self.view];
    [ZMLoadingView showInView:self.view];
}

- (void)dismissLoadingView {
    [ZMLoadingView dismissFromView:self.view];
}

#pragma mark - ZMNavigationBarDelegate
- (void)navigationBar:(ZMNavigationBar *)bar onClickLeftItem:(UIButton *)leftItem {
    
}
- (void)navigationBar:(ZMNavigationBar *)bar onClickRightItem:(UIButton *)rightItem {
    
}

@end
